﻿#define _CRT_SECURE_NO_WARNINGS 1
#include <algorithm>
#include <ios>
#include <iostream>
#include <unordered_map>
#include <vector>
using namespace std;

int main() {
    int n;
    cin >> n;
    unordered_map<int, int> mp;
    vector<int> arr;
    for (int i = 0; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        if (!mp.count(a))
        {
            mp[a] = b;
            arr.push_back(a);
        }
        else if (b < mp[a]) mp[a] = b;
    }
    int len = arr.size();
    sort(arr.begin(), arr.end());
    int rightmax = mp[arr[0]];
    int sum = 1;
    for (int i = 1; i < len; i++)
    {
        if (mp[arr[i]] <= rightmax)
        {
            rightmax = mp[arr[i]];
        }
        else if (arr[i] >= rightmax)
        {
            sum += 1;
            rightmax = mp[arr[i]];
        }
    }
    cout << sum;
    return 0;
}
// 64 位输出请用 printf("%lld")
//1 1 1
//1 0 0
//1 0 0
//1 0 0